# Used for 2-way binding between boolean observable and
# string value property (like on a 'select' element)
ko.bindingHandlers.booleanValue = {
  init: (element, valueAccessor, allBindingsAccessor) =>
    observable = valueAccessor()
    interceptor = ko.computed {
      read: () =>
        observable().toString()
      write: (newValue) =>
        observable newValue is 'true'
    }
    
    ko.applyBindingsToNode(element, {value: interceptor})
}

class window.options_vm
  constructor: (@parent) ->
    @title = ko.observable "Options"
    
    # Notification Preferences
    @push_notifications = ko.observable true
    
    # Account Settings
    @user_name = ko.observable "user001"
    
    # Facebook
    @facebook_canFind = ko.observable false
    @facebook_isLinked = ko.observable false
    
  Tap_PickFriends: (d, e) =>
    @parent.Navigate Templates.PICK_FRIENDS
    
  Tap_LinkFacebook: (d, e) =>
    console.log "Linking to Facebook!"
    @facebook_isLinked true
    # Can't figure out why the flip switch won't enable by itself...
    # It works automatically if you hit 'Back' and re-enter the Options page...
    $('#flip-facebook-canfind').slider('enable')
  
  Save: (d, e) =>
    @parent.Navigate Templates.HOME
